package com.panfeng.xcloud.scheduler.service;

import com.alibaba.fastjson.JSONObject;
import com.binance.client.model.enums.CandlestickInterval;
import com.panfeng.xcloud.boss.provider.dto.request.QuantBotDetailDTO;
import com.panfeng.xcloud.common.core.candle.MyCandleEntry;
import com.panfeng.xcloud.common.core.enums.MovingAverageIndexEnum;
import com.panfeng.xcloud.common.core.enums.MovingAveragePeriodEnum;
import org.ta4j.core.BarSeries;
import org.ta4j.core.num.Num;

import java.math.BigDecimal;
import java.time.Duration;
import java.util.List;

public interface ITechniqueSymbolService {

    //---------------------------------------------------MA均线多头空头判断-------------------------------------------------

    /**
     * ma均线多头排列开多判断
     */
    Boolean maBuyRange_Open(float[] ma_Low, float[] ma_Mid, float[] ma_High);

    /**
     * ma均线空头排列开空判断
     */
    Boolean maSellRange_Open(float[] ma_Low, float[] ma_Mid, float[] ma_High);

    /**
     * ma均线空头排列平多判断
     */
    Boolean maBuyRange_Close(float[] ma_High);

    /**
     * ma均线多头排列平空判断
     */
    Boolean maSellRange_Close(float[] ma_High);
    //----------------------------------------------------------------------------------------------------------------------

    //---------------------------------------------------MA均线斜率判断-------------------------------------------------

    /**
     * ma均线斜率开多判断
     */
    Boolean maBuySlope_Open(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO, BigDecimal minDegree,
                            BigDecimal maxDegree, MovingAveragePeriodEnum maPeriod,
                            MovingAverageIndexEnum index1, MovingAverageIndexEnum index2) throws Exception;

    /**
     * 开多两ma均线大小判断
     */
    Boolean twoMaBuySlopeJudge_Open(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO,
                                    BigDecimal minDegree, BigDecimal maxDegree, MovingAveragePeriodEnum maPeriod,
                                    MovingAverageIndexEnum index1, MovingAverageIndexEnum index2,
                                    MovingAverageIndexEnum index3, MovingAverageIndexEnum index4) throws Exception;

    /**
     * ma均线斜率开空判断
     */
    Boolean maSellSlope_Open(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO, BigDecimal minDegree,
                             BigDecimal maxDegree, MovingAveragePeriodEnum maPeriod,
                             MovingAverageIndexEnum index1, MovingAverageIndexEnum index2) throws Exception;

    /**
     * 开空两ma均线大小判断
     */
    Boolean twoMaSellSlopeJudge_Open(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO,
                                     BigDecimal minDegree, BigDecimal maxDegree, MovingAveragePeriodEnum maPeriod,
                                     MovingAverageIndexEnum index1, MovingAverageIndexEnum index2,
                                     MovingAverageIndexEnum index3, MovingAverageIndexEnum index4) throws Exception;

    /**
     * ma均线斜率平多判断
     */
    Boolean maBuySlope_Close(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO, BigDecimal maxDegree,
                             MovingAveragePeriodEnum maPeriod, MovingAverageIndexEnum index1, MovingAverageIndexEnum index2) throws Exception;

    /**
     * ma均线斜率平空判断
     */
    Boolean maSellSlope_Close(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO, BigDecimal minDegree,
                              MovingAveragePeriodEnum maPeriod, MovingAverageIndexEnum index1, MovingAverageIndexEnum index2) throws Exception;

    /**
     * ma均线多单偏离值判断
     */
    Boolean maBuySlope_Departure(JSONObject candleStick, QuantBotDetailDTO quantBotDetailDTO, MovingAveragePeriodEnum maPeriod) throws Exception;

    /**
     * ma均线空单偏离值判断
     */
    Boolean maSellSlope_Departure(JSONObject candleStick, QuantBotDetailDTO quantBotDetailDTO, MovingAveragePeriodEnum maPeriod) throws Exception;

    /**
     * 开多向上三线开花判断
     */
    Boolean judgeBuyFlower(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO, MovingAveragePeriodEnum smallMaPeriod,
                           MovingAveragePeriodEnum midMaPeriod, MovingAveragePeriodEnum bigMaPeriod, MovingAverageIndexEnum index,
                           MovingAverageIndexEnum degreeIndex1, MovingAverageIndexEnum degreeIndex2) throws Exception;

    /**
     * 开空向下三线开花判断
     */
    Boolean judgeSellFlower(CandlestickInterval interval, QuantBotDetailDTO quantBotDetailDTO, MovingAveragePeriodEnum smallMaPeriod,
                            MovingAveragePeriodEnum midMaPeriod, MovingAveragePeriodEnum bigMaPeriod, MovingAverageIndexEnum index,
                            MovingAverageIndexEnum degreeIndex1, MovingAverageIndexEnum degreeIndex2) throws Exception;

    /**
     * 获取某根均线值
     */
    BigDecimal getMa(JSONObject candleStick, MovingAveragePeriodEnum maPeriod, MovingAverageIndexEnum index) throws Exception;

    /**
     * 开多均线金叉判断
     */
    Boolean goldCrossOpen(JSONObject candleStick, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 开空均线死叉判断
     */
    Boolean deathCrossOpen(JSONObject candleStick, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 运行过程中均线金叉判断
     */
    Boolean goldCrossRunning(JSONObject candleStick, MovingAveragePeriodEnum shortMa, MovingAveragePeriodEnum longMa, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 运行过程中均线金叉是否确认成立判断
     */
    Boolean judgeBuyTendencyRunning(List<MyCandleEntry> candleEntries, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 运行过程中均线死叉判断
     */
    Boolean deathCrossRunning(JSONObject candleStick, MovingAveragePeriodEnum shortMa, MovingAveragePeriodEnum longMa, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 运行过程中均线死叉是否确认成立判断
     */
    Boolean judgeSellTendencyRunning(List<MyCandleEntry> candleEntries, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    //----------------------------------------------------------------------------------------------------------------------

    //---------------------------------------------------蜡烛图判断-------------------------------------------------

    /**
     * 获取某根蜡烛
     */
    List<MyCandleEntry> getCandlerStick(JSONObject candleStick, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 获取某段时间内最大成交量
     */
    BigDecimal getHighestVolume(List<MyCandleEntry> candleEntries, int index, int period) throws Exception;

    /**
     * 开多吞没pinbar判断
     */
    Boolean judgeBuyPinBarOpen(JSONObject candleStick, MovingAveragePeriodEnum shortMa, MovingAveragePeriodEnum midMa, MovingAveragePeriodEnum longMa, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 开空吞没pinbar判断
     */
    Boolean judgeSellPinBarOpen(JSONObject candleStick, MovingAveragePeriodEnum shortMa, MovingAveragePeriodEnum midMa, MovingAveragePeriodEnum longMa, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 开多趋势中pinbar判断
     */
    Boolean judgeTrendBuyPinBarOpen(JSONObject candleStick, MovingAveragePeriodEnum shortMa, MovingAveragePeriodEnum midMa, MovingAveragePeriodEnum longMa, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 开多趋势中突破判断
     */
    Boolean judgeTrendBuyBreakThroughOpen(JSONObject candleStick5m, int atrPeriod, QuantBotDetailDTO quantBotDetailDTO, Duration barSeriesTimePeriod) throws Exception;

    Boolean judgeTrendBuyBreakThroughOpen2(JSONObject candleStick5m, int atrPeriod, QuantBotDetailDTO quantBotDetailDTO, Duration barSeriesTimePeriod) throws Exception;

    /**
     * 开空趋势中pinbar判断
     */
    Boolean judgeTrendSellPinBarOpen(JSONObject candleStick, MovingAveragePeriodEnum shortMa, MovingAveragePeriodEnum midMa, MovingAveragePeriodEnum longMa, QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 开空趋势中突破判断
     */
    Boolean judgeTrendSellBreakThroughOpen(JSONObject candleStick5m, int atrPeriod, QuantBotDetailDTO quantBotDetailDTO, Duration barSeriesTimePeriod) throws Exception;

    Boolean judgeTrendSellBreakThroughOpen2(JSONObject candleStick5m, int atrPeriod, QuantBotDetailDTO quantBotDetailDTO, Duration barSeriesTimePeriod) throws Exception;

    //---------------------------------------------------ATR-------------------------------------------------

    /**
     * 获取今日浮动盈亏
     *
     * @return
     */

    BigDecimal getTodayFloatProfit(QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 获取今日已实现盈亏
     *
     * @return
     */
    BigDecimal getTodayRealizedProfit(QuantBotDetailDTO quantBotDetailDTO) throws Exception;

    /**
     * 计算rsi值
     *
     * @return
     */
    BigDecimal getRsi(BarSeries barSeries, int rsiTimeFrame, int index);

    BarSeries getBarSeries(List<MyCandleEntry> candleEntries, Duration timePeriod);

    List<Num> getMACDvalue(BarSeries barSeries, int shortPeriod, int longPeriod);

    List<Num>[] getMACD_signal_value(BarSeries barSeries, int shortPeriod, int longPeriod, int signalPeriod);

    List<Num> getMACDhistogram(BarSeries barSeries, int shortPeriod, int longPeriod, int signalPeriod);

    List<Num> getATR(BarSeries barSeries, int atrPeriod);

    BigDecimal[] getDepthVolume(QuantBotDetailDTO quantBotDetailDTO, BigDecimal ratioLimit) throws Exception;

}
